package String;

import java.util.Scanner;

public class equal_username_password {
    public static void main(String[] args) {
        //已知正确的用户名和密码，请用程序实现模拟用户登录，总共给三次机会，登录之后，给出相应的提示

        //1.定义两个变量记录正确的用户名和密码
        String rightUsername = "zhangsan";
        String rightPassword = "123456";


        //键盘录入用户名和密码
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < 3; i++) {
            System.out.println("Username:");
            String username = sc.next();
            System.out.println("Password:");
            String password = sc.next();

            //比较
            if (username.equals(rightUsername) && password.equals(rightPassword)) {
                System.out.println("用户登陆成功");
                break;
            }
            else if(i==2){
                System.out.println("账号"+username+"被锁定，请联系：xxxxxx");
            }
            else {
                System.out.println("用户登录失败,用户名或密码有误，您还剩下"+(2-i)+"次机会");
            }
        }
    }
}
